/**
 * 
 */
package com.device.grant.dao.impl;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Repository;

import com.device.grant.dao.BaseDao;
import com.device.grant.dao.DepartmentDao;
import com.device.grant.pojo.IDepartment;
import com.device.grant.utils.ColumnCompator;
import com.device.grant.utils.SQLUtils2;

/**
 * @author zhuxy
 * 
 * @version 1.0
 */
@Repository("departmentDao")
public class DepartmentDaoImpl extends BaseDao<IDepartment> implements DepartmentDao {

    private static final String TABLE = "IDepartment";

    private static final String ID = "DeptID";

    public List<IDepartment> getDepartMents(Integer page, Integer rows, Map<String, Object> params, List<String> blearParams,
            Map<String, ColumnCompator> compators, String orderBy) {
        String sql = SQLUtils2.genearlQuerySQLForCompareAndNotIn(TABLE, ID, page, rows, params, blearParams, compators, orderBy);

        return super.queryInSQL(sql);
    }

    public Integer getQueryCount(Map<String, Object> params, List<String> blearParams, Map<String, ColumnCompator> compators) {
        Map<String, Object> map = SQLUtils2.generalCountSQLForCompare(TABLE, ID, params, blearParams, compators);

        return simpleJdbcTemplate.queryForInt(map.get(SQLUtils2.SQL).toString(), (Object[]) map.get(SQLUtils2.PARAMS));
    }

    public boolean insertDepartment(IDepartment iDepartment) {
        return super.insert(TABLE, ID, iDepartment);
    }

    public List<IDepartment> getDepartMentsIncludeParent(Set<Integer> ids) {
        return super.queryInKeys(TABLE, ID, null, ids);
    }

    public boolean updateDepartMentByBean(IDepartment department) {
        Map<String, Object> map = SQLUtils2.generalUpdateSQLFromBean(department, ID, TABLE);

        int result = simpleJdbcTemplate.update(map.get(SQLUtils2.SQL).toString(), (Object[]) map.get(SQLUtils2.PARAMS));

        return (result < 0) ? false : true;
    }

    public IDepartment getTheDepartmentVo(Map<String, Object> conditions) {
        return super.get(TABLE, conditions);
    }

}
